package me.muci.A_base.processingFlow;

import java.io.*;

/**
 * ClassName: BufferedRWTest
 * <p>
 * Description:
 * <p>
 * date: 2021/8/12 13:51
 *
 * @author muci
 * @since JDK 1.8
 */
public class BufferedReWrTest {

    public void copy(String srcPath, String tarPath) {
        try (
                BufferedReader br = new BufferedReader(new FileReader(new File(srcPath)));
                BufferedWriter bw = new BufferedWriter(new FileWriter(new File(tarPath)));
        ) {
            //1. 方式1
//            char[] chars = new char[1024];
//            int len;
//            while ((len = br.read(chars)) != -1) {
//                bw.write(chars, 0, len);
//            }
            // 2.方式2
            String data;
            while ((data = br.readLine()) != null){
                // 写入时，不会写入换行符，需要自己创建
                bw.write(data);
                bw.newLine();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
